<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<html>
    <body>
        <p>
            ${msg}
        </p>
        <c:choose>
            <c:when test="${user == null}">
                <p>
                    Hello!<a href="${loginUrl}">Sign in</a>
                    to include your name with greetings you post.
                </p>
            </c:when>
            <c:otherwise>
                <p>
                    Hello, ${user.nickname}! (You can <a href="${logoutUrl}">sign out</a>.)
                </p>
            </c:otherwise>
        </c:choose>
        <form action="/test/sign.htm" method="post">
            <div>
                <textarea name="content" rows="3" cols="60"></textarea>
            </div>
            <div>
                <input type="submit" value="Post Greeting" />
            </div>
        </form>
        <br/>
        <c:choose>
            <c:when test="${greetings == null}">
                <p>
                    The guestbook has no messages.
                </p>
            </c:when>
            <c:otherwise>
                <c:forEach items="${greetings}" var="g" varStatus="status">
                    <c:choose>
                        <c:when test="${g.author == null}">
                            <p>
					            An anonymous person wrote:
					        </p>
                        </c:when>
                        <c:otherwise>
                            <p>
					            <b>${g.author.nickname}</b>
					            wrote:
					        </p>
                        </c:otherwise>
                    </c:choose>
					<blockquote>
						${g.content}
			        </blockquote>
                </c:forEach>
            </c:otherwise>
        </c:choose>
        <br/>
    </body>
</html>
